package com.hx.zhg.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NumberUtilExt {
    public static Integer strToInteger(String val) {
        Integer result = null;
        try {
            result = Integer.parseInt(val);
        } catch (Exception e) {
        }
        return result;
    }

    public static Float strToFloat(String val) {
        Float result = null;
        try {
            result = Float.parseFloat(val);
        } catch (Exception e) {
        }
        return result;
    }

    public static Double strToDouble(String val) {
        Double result = null;
        try {
            result = Double.parseDouble(val);
        } catch (Exception e) {
        }
        return result;
    }

    /**
     * 利用正则表达式判断字符串是否是数字
     *
     * @param str
     * @return
     */
    public static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }
}
